$(document).ready(function(){


	$.get('dashboard/getListings', function(data){
		for (var i = 0; i < data.length; i++) {

			$('.listInserts').append('<div class="comment_container">' + data[i].textdata + ' <button class="delete fa fa-times-circle" rel="' + data[i].id + '"></button>' + '</div>');	
		}
		

	}, 'json');


	$('body').on('click', '.delete', function(){
		var id = $(this).attr('rel');
		//alert(id);
		$(this).parent().remove();
		$.post('dashboard/deleteListings', {'id':id}, function(data){});
	});

	$('#randomInsert').submit(function(){
		var url = $(this).attr('action');
		var data = $(this).serialize();
	
		
		$.post(url, data, function(data){


			 $('#textdata').blur(function(){

			 	if ($.trim($(this).val().length == 0 )){
					alert('please add text');
				};

			 });

			
			$('.listInserts').prepend('<div class="comment_container">' + data.textdata + ' <button class="delete fa fa-times-circle" rel="'+ data.id +'"></button>' + '</div>');
			$('#textdata').val('');

			
		}, 'json');

		
		return false;

	});


});